//
package user.ucm;




import db.UserValidate;

import user.model.UserModel;
import user.view.LoginView;


public class UCLogining implements UCController{

    private UserModel um;
  //  private SituModel sm;

    public UCLogining(UserModel um) {
        this.um = um;
       // this.sm = sm;
    }

    public int run() {
       
    	int rs;
    	if(um.getName().trim().equals("")){rs= -1;
    	LoginView.getInstance().updateResult(rs,um.getType(),um.getName());
        return 1;
    	}
        if(um.getPsw().trim().equals("")){rs= -2;
        LoginView.getInstance().updateResult(rs,um.getType(),um.getName());
        return 1;
        }
    	
    	if(UserValidate.isValidUser(um)){
    		if(UserValidate.isOnline(um.getName(), um.getType()))
    		{
    			LoginView.getInstance().updateResult(-3,um.getType(),um.getName());
    			return 1;
    		}
        	rs= 1;
        	LoginView.getInstance().updateResult(rs,um.getType(),um.getName());
            return 1;
        }
        rs= 0;
        LoginView.getInstance().updateResult(rs,um.getType(),um.getName());
        return 1;
        
    }
}
